/**********************************************************************
*  Copyright (c) 2007 - Victor Jacobs - victor.jacobs@gmail.com
*
*  Permission is hereby granted, free of charge, to any person
*  obtaining a copy of this software and associated documentation
*  files (the "Software"), to deal in the Software without
*  restriction, including without limitation the rights to use,
*  copy, modify, merge, publish, distribute, sublicense, and/or sell
*  copies of the Software, and to permit persons to whom the
*  Software is furnished to do so, subject to the following
*  conditions:
*
*  The above copyright notice and this permission notice shall be
*  included in all copies or substantial portions of the Software.
*
*  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
*  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
*  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
*  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
*  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
*  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
*  OTHER DEALINGS IN THE SOFTWARE.
**********************************************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace Vj.MathLibrary
{
    public class RandomGrabber
    {
        private static Random myRandom;

        static RandomGrabber()
        {
            Reset();
        }

        public static void Reset()
        {
            myRandom = new Random(Environment.TickCount);
        }

        // get random int between 0 and int.MaxValue
        public static int Next()
        {
            return myRandom.Next();
        }

        // get random int between 0 and max
        public static int Next(int max)
        {
            if (max < 0 || max > int.MaxValue)
                throw new ArgumentOutOfRangeException();

            return myRandom.Next(max);
        }
        
        // get random bool
        public static bool NextBoolean()
        {
            if (myRandom.Next(0, 2) == 0)
                return false;
            else
                return true;
        }

        // get random double between 0.0 and 1.0
        public static double NextDouble()
        {
            double rn = myRandom.NextDouble();
            return rn;
        }

        // get random in between min and max
        public static int Next(int min, int max)
        {
            if (max <= min)
                throw new ArgumentException("Max must be greater than Min.");

            return myRandom.Next(min, max);
        }

        // get random float between min and max
        public static float Next(float min, float max)
        {
            if (max <= min)
                throw new ArgumentException("Max must be greater than Min.");

            float rn = (max - min) * (float)myRandom.NextDouble() + min;
            return rn;
        }

        // get random double between min and max
        public static double Next(double min, double max)
        {
            if (max <= min)
                throw new ArgumentException("Max must be greater than Min.");

            double rn = (max - min) * myRandom.NextDouble() + min;
            return rn;
        }

        public static Color NextColor()
        {
            return Color.FromArgb(myRandom.Next(255), myRandom.Next(255), myRandom.Next(255));
        }
    }
}
